﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Restaurant.BusinessEntity;

namespace Restaurant.Repository.Mapping
{
    public class AperturaCajaMap:EntityTypeConfiguration<AperturaCaja>
    {
        public AperturaCajaMap()
        {
            this.HasKey(r => r.Id);

            //propiedades
            this.Property(r => r.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(r => r.Fecha)
                .IsRequired();

            this.Property(r => r.MontoInicial)
               .IsRequired();

            //table
            this.ToTable("AperturaCaja");

            //Relaciones
            this.HasRequired(r => r.Trabajador)
                .WithMany(t=>t.AperturaCajas)
                .HasForeignKey(r => r.IdTrabajador)
                .WillCascadeOnDelete(false);

            this.HasRequired(r => r.Caja)
                .WithMany(t => t.AperturaCajas)
                .HasForeignKey(r => r.IdCaja)
                .WillCascadeOnDelete(false);
        }
    }
}
